package com.example.q_kang.hhh.setting;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.q_kang.hhh.R;
import com.hjq.toast.ToastUtils;
import com.sskj.base.MVPActivity;
import com.sskj.base.base.App;
import com.sskj.base.utils.ClickUtil;
import com.sskj.base.view.ToolBarLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author Hey
 * Create at  2019/04/10
 */
public class UserInfoActivity extends MVPActivity<UserInfoPresenter> {


    @BindView(R.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R.id.et_nickname)
    EditText etNickname;
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.et_remark)
    EditText etRemark;
    @BindView(R.id.btn_submit)
    Button btnSubmit;

    @Override
    public int getLayoutId() {
        return R.layout.activity_user_info;
    }

    @Override
    public UserInfoPresenter getPresenter() {
        return new UserInfoPresenter();
    }

    @Override
    public void initView() {
        toolbar.setLeftButtonOnClickListener(view -> finish());
        ClickUtil.click(300, btnSubmit, new ClickUtil.Click() {
            @Override
            public void click(View view) {
                if (TextUtils.isEmpty(etNickname.getText().toString())) {
                    ToastUtils.show(App.INSTANCE.getString(R.string.appJavaUserInfoActivity1));
                    return;
                }
                if (TextUtils.isEmpty(etName.getText().toString())) {
                    ToastUtils.show(App.INSTANCE.getString(R.string.appJavaUserInfoActivity2));
                    return;
                }
                if (TextUtils.isEmpty(etRemark.getText().toString())) {
                    ToastUtils.show(App.INSTANCE.getString(R.string.appJavaUserInfoActivity3));
                    return;
                }
                mPresenter.editData(etNickname.getText().toString(),
                        etName.getText().toString(),
                        etRemark.getText().toString());
            }
        });
    }

    @Override
    public void initData() {
        etNickname.setText(getIntent().getStringExtra("nickname"));
        etName.setText(getIntent().getStringExtra("realname"));
        etRemark.setText(getIntent().getStringExtra("pb_note"));
    }

    public static void start(Context context, String realname, String nickname, String pb_note) {
        Intent intent = new Intent(context, UserInfoActivity.class);
        intent.putExtra("realname", realname);
        intent.putExtra("nickname", nickname);
        intent.putExtra("pb_note", pb_note);
        context.startActivity(intent);
    }

    public void setUserDataSuccess() {
        finish();
    }
}
